{extend name="shop/blue/base" /}
{block name="resources"}
<style type="text/css">
td{padding:10px;border: 1px Black; width:46px;}
table{background-color:#eeeeee;border:0;width:100%;}
.integral_title{display:block;font-size:18px;text-align:center;padding:20px;}
.member-main .tabmenu .tab li {border-bottom: 2px #ff6600 solid;}
.right-function{float:right;margin: 0 10px;line-height: 30px;font-size:14px;}
</style>
{/block}
{block name="main"}
<div class="margin-w1210">
	{include file='shop/blue/Member/controlLeftMenu'/}
	<input type="hidden" value="{$account}" id="subscription"/>
	<div class="member-main">
		<div class="box" id="firstpage">
			<div class="tabmenu">
				<ul class="tab">
					<li class="active">我的积分</li>
				</ul>
			</div>
			<div class="member-data-header">
				<span class="member-data-title">
					{if condition="!isset($shopname)"}
					{$platform_shopname}
					{else /}
					{$shopname}
					{/if}
					<span>(积分:<span class="sum">{$sum}</span>)</span>
				</span>
				
				<div class="right-function">
					{if condition="$shop_id == 0"}
					<a href="javascript:;" id="extract">兑换余额</a>&nbsp;|
					{/if}
					<a href="{:__URL('SHOP_MAIN/member/integrallist')}">我的积分</a>
				</div>
			</div>
			{if condition="$total_count neq ''"}
			<table>
				<tr align="center">
					<td>类别</td>
					<td>数量</td>
					<td>描述</td>
					<td>时间</td>
				</tr>
				<tbody id="list_content" class="close-order">
					{foreach $balances.data as $balance}
					<tr align="center">
						<td>{$balance.type_name}</td>
						<td>{$balance.number}</td>
						<td>{$balance.text}</td>
						<td>{$balance.create_time | getTimeStampTurnTime}</td>
					</tr>
					{/foreach}
				</tbody>
			</table>
			{include file='shop/blue/controlCommonPage'/}
			{else/}
			<div>
				<div class="emptyFrame"> <i class="user_point"></i><span>您暂时还没有积分哦！</span> </div>
			</div>
			{/if}
		</div>
		<div class="box" id="secondpage" style="display:none;">
			
			<div class="tabmenu">
				<ul class="tab">
					<li class="active">兑换余额</li>
				</ul>
			</div>
			
			
			<div class="member-data-header">
				<span class="member-data-title">
					{if condition="!isset($shopname)"}
					{$platform_shopname}
					{else /}
					{$shopname}
					{/if}
					<span>(积分:<span class="sum">{$sum}</span>)</span>
				</span>
				
				<div class="right-function">
					<a href="javascript:;" id="extract2">积分明细</a>&nbsp;|
					<a href="{:__URL('SHOP_MAIN/member/integrallist')}">我的积分</a>
				</div>
			</div>
			<form name="formSurplus" method="post" action="{:__URL('SHOP_MAIN/member/exchange')}" id="formsubmit">
				<input type="hidden" name="shopid" value="{$shop_id}" /> 
				<table width="100%" border="0" cellpadding="10" cellspacing="1" bgcolor="#eeeeee">
					<tr>
						<td width="10%" align="right">兑换积分数:</td>
						<td align="left">
							<input type="text" name="amount" class="inputBg" size="30" min="0" max="{$sum}" style="width:86px;border:1px solid #ccc;"/>
							<span style="display:inline-block;" id="proving"></span>
						</td>
					</tr>
					<tr>
						<td width="10%" align="right"><span style="display:inline-block;">可用积分为<span id="number">{$sum} </span></span></td>
						{if condition="$account !=null && $account>0"}
						<td align="left">兑换比例为1积分兑换{$account}元</td>
						{else/}
						<td align="left">当前店铺未配置积分兑换</td>
						{/if}
					</tr>
					<tr>
						<td colspan="2" align="center">
							<input type="hidden" name="surplus_type" value="1" />
							<input type="hidden" name="act" value="act_account" />
							{if condition="$account!=null && $account>0"}
							<input type="submit" name="submit" class="common-btn" value="兑换" />
							<input type="hidden" id="hidden_account" value="{$account}" />
							{else/}
							<input type="submit" name="submit" class="common-btn-disabled" value="兑换" disabled="disabled" />
							{/if}
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</div>
{/block}
{block name="RightSideBar"}{/block}
{block name="javascript"}
<script>
$(document).ready(function(){
	var max = parseInt($("input[name='amount']").attr("max"));		//最大余额
	var number = $("#number").text();								//可用积分
	var yz = false;													//验证条件
	var subscription = $("#subscription").val();					//兑换比例
	//点击进入积分兑换
	$("#extract").on("click",function(){
		number = $(".sum").text();
		$("#firstpage").hide();
		$("#secondpage").show();
	});
	//点击返回余额明细界面
	$("#extract2").on("click",function(){
		$("#firstpage").show();
		$("#secondpage").hide();
		$("input[name='amount']").val("");
	});
	//左侧菜单栏选中效果
	$("#qiye_point").addClass('curs');
	//选中积分提示效果
	$("input[name='amount']").on("keyup",function(){
		var getnumber = $("input[name='amount']").val();//输入框中输入的积分
		var re = /^[0-9]*[1-9][0-9]*$/ ;
			if(subscription == 0){
				$(this).css("border","1px solid red");
				$("#proving").text("不可兑换余额,请修改兑换比例").css("color","red");
				yz = false;
				is_ok
			}else if(!re.test(getnumber)){
				$(this).css("border","1px solid red");
				$("#proving").text("积分必须为整数").css("color","red");
				yz = false;
			}else if(getnumber.search(/[^\-?\d.]/g) == -1){
					var stringToNumber = parseFloat(getnumber);
					if(stringToNumber>0 && stringToNumber<=max){
						var result = subscription*stringToNumber;
						$(this).css("border","1px solid #ccc");
						$("#proving").text("兑换金额为¥"+result.toFixed(2)).css("color","red");	
						yz = true;
					}else{
						$(this).css("border","1px solid red");
						$("#proving").text("最大可兑换"+number+"积分").css("color","red");
						yz = false;
					}
			}else{
				$(this).css("border","1px solid red");
				$("#proving").text("请输入正确的积分格式").css("color","red");
				yz = false;
			}
	});
	$("input[name='submit']").on("click",function(){
		if($("#hidden_account").val() == undefined || $("#hidden_account").val() == "" || parseFloat($("#hidden_account").val()) == 0){
			$.msg("当前店铺未设置余额兑换");
			return false;
		}
		if(yz){
			$("#formsubmit").submit();
		}else{
			$("input[name='amount']").trigger("focus");
			return false;
		}
	});
});
</script>
{/block}